package org.dromara.common.model.enums.channel;

/**
 * 频道类型
 * @author Stars
 */
public enum ChannelTypeEnum {
    PERSONAL_CHANNEL(1, "个人频道"),
    GROUP_CHANNEL(2, "群聊频道");

    private final int code;
    private final String description;

    ChannelTypeEnum(int code, String description) {
        this.code = code;
        this.description = description;
    }

    public int getCode() {
        return code;
    }

    public String getDescription() {
        return description;
    }

    /**
     * 根据频道类型代码获取对应的类型描述
     * @param code 频道类型代码
     * @return 对应的类型描述，如果未找到则返回 null
     */
    public static String getDescriptionByCode(int code) {
        for (ChannelTypeEnum type : values()) {
            if (type.getCode() == code) {
                return type.getDescription();
            }
        }
        return null;
    }

    /**
     * 根据频道类型代码获取对应的枚举实例
     * @param code 频道类型代码
     * @return 对应的枚举实例，如果未找到则返回 null
     */
    public static ChannelTypeEnum getByCode(int code) {
        for (ChannelTypeEnum type : values()) {
            if (type.getCode() == code) {
                return type;
            }
        }
        return null;
    }
}
